#include <Dynamics/Damping/velocity_damping_cpu.h>

namespace PhysLeo
{
    
template<typename T>
void VelocityDampingCpu<T>::allocateResource(SimData<T>& simData)
{
    ptr_mass_ = simData.ptr_mass_;
    velocity_damping_param_ = simData.velocity_damping_param_;
}

template<typename T>
void VelocityDampingCpu<T>::addDampingForce(std::shared_ptr<BufferData<glm::tvec3<T>>> vel, std::shared_ptr<BufferData<glm::tvec3<T>>> force)
{
    auto mass_ptr = ptr_mass_->ptrCpu();
    auto vel_ptr = vel->ptrCpu();
    auto force_ptr = force->ptrCpu();

    const int vert_num = ptr_mass_->size();
    for(auto vert_id=0;vert_id<vert_num;++vert_id)
    {
        force_ptr[vert_id] += -velocity_damping_param_ * mass_ptr[vert_id] * vel_ptr[vert_id];
    }
}

template class VelocityDampingCpu<float>;
template class VelocityDampingCpu<double>;

}